﻿

'*******************************************************************
' Program: Data Center Visio Rack Tool
' Author: Albert E Edlund
' Date:
'
' Purpose: Where portbase is required for all known ports in the configuration
' portdata is used for cabled/connected ports
'
'
'
'*******************************************************************


Imports Microsoft.Practices.EnterpriseLibrary.Common
Imports Microsoft.Practices.EnterpriseLibrary.Data
Imports Microsoft.Practices.EnterpriseLibrary.ExceptionHandling
Imports Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging


Imports System
Imports System.ComponentModel
Imports System.Collections.Generic

Imports visRackLocations.dc_PortBase


Public Class dc_Port
    Inherits dc_PortBase
    Implements INotifyPropertyChanged


#Region "Events"

    Public Event PropertyChanged(ByVal sender As Object, ByVal e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged

    Private Sub OnPropertyChanged(ByVal info As String)
        RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(info))
    End Sub

#End Region

#Region " Constructor "

    Public Sub New()
        initPortProperties()
    End Sub

    Public Sub New(ByVal strUserId As String)
        initPortProperties()
        Me.m_portLastEdit = strUserId
    End Sub

#End Region

#Region " Enumerations "
    '
    ' portStatus
    '
    Public Enum enumPortStatus
        statusUninitialized = -1
        statusActive = 0
        statusErrors = 1
        statusAdminDown = 2
        statusUnknown = 3
    End Enum

    '
    '
    '
    Public Enum enumPortDuplex
        dpxUnknown = -1
        dpxHalf = 1
        dpxFull = 2
        dpxSimplex = 3
    End Enum

#End Region

#Region " Properties and Fields "

    Shadows constPortProductKey As Int32 = -1
    Shadows constPortName As String = "na"
    Shadows constPortProductView As dc_Product.View = dc_Product.View.viewRear
    Shadows constPortTechnology As Int16 = PortTech.techUnknown
    Shadows constPortConnector As Int16 = PortConn.connUnknown



    Private m_portKey As Int32
    Public Const constPortKey As Int32 = -1
    Public Property portKey() As Int32
        Get
            Return Me.m_portKey
        End Get
        Set(ByVal value As Int32)
            Me.m_portKey = value
            Me.OnPropertyChanged("portKey")
        End Set
    End Property

    Private m_portCompKey As Int32
    Public Const constPortCompKey As Int32 = -1
    Public Property portCompKey() As Int32
        Get
            Return Me.m_portCompKey
        End Get
        Set(ByVal value As Int32)
            Me.m_portCompKey = value
            Me.OnPropertyChanged("portCompKey")
        End Set
    End Property

    Private m_portSpeed As Int32
    Public Const constPortSpeed As Int32 = 0
    Public Property portSpeed() As Int32
        Get
            Return Me.m_portSpeed
        End Get
        Set(ByVal value As Int32)
            Me.m_portSpeed = value
            Me.OnPropertyChanged("portSpeed")
        End Set
    End Property

    Private m_portStatus As enumPortStatus
    Public Const constPortStatus As enumPortStatus = enumPortStatus.statusUnknown
    Public Property portStatus() As enumPortStatus
        Get
            Return Me.m_portStatus
        End Get
        Set(ByVal value As enumPortStatus)
            ' Checks to see if the value passed is valid.
            If Not TypeDescriptor.GetConverter(GetType(enumPortStatus)).IsValid(value) Then
                Throw New ArgumentException()
            End If
            Me.m_portStatus = value
            Me.OnPropertyChanged("portStatus")
        End Set
    End Property

    Private m_portDuplex As enumPortDuplex
    Public Const constPortDuplex As enumPortDuplex = enumPortDuplex.dpxFull
    Public Property portDuplex() As enumPortDuplex
        Get
            Return Me.m_portDuplex
        End Get
        Set(ByVal value As enumPortDuplex)
            ' Checks to see if the value passed is valid.
            If Not TypeDescriptor.GetConverter(GetType(enumPortDuplex)).IsValid(value) Then
                Throw New ArgumentException()
            End If
            Me.m_portDuplex = value
            Me.OnPropertyChanged("portDuplex")
        End Set
    End Property

    Private m_portUtilForward As Double
    Public Const constPortUtilForward As Double = 0
    Public Property portUtilForward() As Double
        Get
            Return Me.m_portUtilForward
        End Get
        Set(ByVal value As Double)
            Me.m_portUtilForward = value
            Me.OnPropertyChanged("portUtilForward")
        End Set
    End Property

    Private m_portUtilReverse As Double
    Public Const constPortUtilReverse As Double = 0
    Public Property portUtilReverse() As Double
        Get
            Return Me.m_portUtilReverse
        End Get
        Set(ByVal value As Double)
            Me.m_portUtilReverse = value
            Me.OnPropertyChanged("portUtilReverse")
        End Set
    End Property

    Private m_portComments As String
    Public Const constPortComments As String = "none"
    Public Property portComments() As String
        Get
            Return Me.m_portComments
        End Get
        Set(ByVal value As String)
            Me.m_portComments = value
            Me.OnPropertyChanged("portComments")
        End Set
    End Property


    Private m_portLastUpdate As Date
    Public Const constPortLastUpdate As Date = #1/1/2001#
    Public Property portLastUpdate() As Date
        Get
            Return Me.m_portLastUpdate
        End Get
        Set(ByVal value As Date)
            Me.m_portLastUpdate = value
            Me.OnPropertyChanged("portLastUpdate")
        End Set
    End Property

    Private m_portLastEdit As String
    Public Const constPortLastEdit As String = "na"
    Public Property portLastEdit() As String
        Get
            Return Me.m_portLastEdit
        End Get
        Set(ByVal value As String)
            Me.m_portLastEdit = value
            Me.OnPropertyChanged("portLastEdit")
        End Set
    End Property


#End Region

#Region " Methods "


    Public Sub initPortProperties()

        Try

            portKey = constPortKey
            portCompKey = constPortCompKey
            portProductKey = constPortProductKey
            portName = constPortName
            portProductView = constPortProductView
            portTechnology = constPortTechnology
            portConnector = constPortConnector
            portSpeed = constPortSpeed
            portStatus = constPortStatus
            portDuplex = constPortDuplex
            portUtilForward = constPortUtilForward
            portUtilReverse = constPortUtilReverse
            portComments = constPortComments
            portLastUpdate = Now
            portLastEdit = constPortLastEdit

        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

    End Sub

    '
    ' pass in portstatus return string
    '
    Public Function getEnumPortStatus _
            (ByVal intStatus As enumPortStatus) _
            As String

        Dim strReturn As String = ""

        ' if an invalid status is passed in then make it an unknown so we do not fail
        If Not TypeDescriptor.GetConverter(GetType(enumPortStatus)).IsValid(intStatus) Then
            intStatus = enumPortStatus.statusUnknown
        End If

        Dim myName As enumPortStatus = intStatus
        strReturn = myName.ToString

        Return strReturn

    End Function


#End Region


End Class
